package org.ailoli.aixiang.utils

import java.io.File
import java.util.*


/**
 * Author: Gnod
 * Date: 2021-01-25 10:56
 * 串口工具类
 */
class AxSerialPortUtils {
    companion object{
        fun getSerial_Ports_name(): Array<String>? {
            val Serial_Ports_number: MutableList<String> = ArrayList()
            var type: Array<String>? = null
            val file = File("/dev/")
            val fs = file.listFiles()
            for (f in fs) {
                if (f.name.contains("tty")) {
                    Serial_Ports_number.add(f.name)
                }
            }
            type = Serial_Ports_number.toTypedArray()
            return type
        }
        //获取在设备目录下的，所有串口的具体物理地址，并且存入到数组里面。
//        fun getAllDevicesPath(): Array<String?>? {
//            val devices: Vector<String> = Vector<String>()
//            // Parse each driver
//            val itdriv: Iterator<Driver>
//            try {
//                itdriv = getDrivers().iterator()
//                while (itdriv.hasNext()) {
//                    val driver: Driver = itdriv.next()
//                    val itdev: Iterator<File> = driver.getDevices().iterator()
//                    while (itdev.hasNext()) {
//                        val device: String = itdev.next().getAbsolutePath()
//                        devices.add(device)
//                    }
//                }
//            } catch (e: IOException) {
//                e.printStackTrace()
//            }
//            return devices.toArray(arrayOfNulls<String>(devices.size()))
//        }
    }
}